AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include('shared.lua')

ENT.Resources = {"energy", "coolant", "air", "water", "steam", "heavy water", "ammo_basic", "ammo_explosion", "ammo_fuel", "ammo_pierce", "terrajuice", "titanium", "redterracrystal", "greenterracrystal", "Munitions", "RawTiberium", "ProcessedTiberium", "TBARS", "TiberiumChemicals", "Petrol", "Oil", "12V Energy", "Crude Oil", "hydrogen", "methane", "nitrous", "nitrogen", "propane", "naturalgas", "darkmatter", "refineddarkmatter", "LiquidTiberium", "Raw Naquadah", "ReNaquadah", "WGNaquadah", "Naquadria", "oxygen", "carbon dioxide"}
ENT.MaxAmount = 5000000000

function ENT:SpawnFunction(ply, tr)
	if(!tr.Hit) then return end
	local ent = ents.Create("black_hole_cache")
	ent:SetPos(tr.HitPos + (tr.HitNormal * 16))
	ent:Spawn()
	ent:Activate()
	return ent
end

function ENT:Initialize()
	self.Entity:SetModel("models/Combine_Helicopter/helicopter_bomb01.mdl")
	self.Entity:PhysicsInit(SOLID_VPHYSICS)
	self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
	self.Entity:SetSolid(SOLID_VPHYSICS)
	
	self.Entity:SetColor(0, 0, 0, 255)
	self.Entity:SetMaterial("models/shiny")
	
	for k, res in pairs(self.Resources) do
		RD.AddResource(self.Entity, res, self.MaxAmount)
	end
	
	local Phys = self.Entity:GetPhysicsObject()
	if(Phys:IsValid()) then
		Phys:Wake()
	end
	
	if(WireAddon != nil) then
		self.WireDebugName = self.PrintName
		self.Outputs = Wire_CreateOutputs(self.Entity, {"Resource Amount"})
		Wire_TriggerOutput(self.Entity, "Resource Amount", self.MaxAmount)
	end
end

function ENT:Think()
	for k, res in pairs(self.Resources) do
		if(RD.GetResourceAmount(self.Entity, res) < self.MaxAmount) then
			RD.SupplyResource(self.Entity, res, self.MaxAmount)
		end
	end
	self.Entity:NextThink(CurTime() + 1)
	return true
end

function ENT:OnRemove()
	Dev_Unlink_All(self.Entity)
end
